// 专门处理路由的文件
const Router = require("koa-router");

const { register, login, updatePassword } = require("../controller/user.controller");
const { userValidator, verifyUser, crpytPassword, verifyLogin, equalToPassword } = require("../middleware/user.middleware"); //导入验证中间件
const { authenticate } = require("../middleware/auth.middlerware");
const router = new Router({ prefix: "/users" });

// 抽离视图函数到controller
router.get("/", (ctx, next) => {
  ctx.body = "ok";
});
// 注册接口
router.post("/register", userValidator, verifyUser, crpytPassword, register);

// 登录接口
router.post("/login", userValidator, verifyLogin, login);

// 密码修改接口
router.patch("/update", authenticate, equalToPassword, crpytPassword, updatePassword);

module.exports = router;
